import { useEffect, useRef, useState } from "react";
import HomePage_TableComponent from "../../../../component/table"
import { $Http } from "../../../../../../network";
import { $eventBus, $EventBus_off, $EventBus_on } from "../../../../../../common/utils";
import { message } from "antd";

// 主页-操作日志页面
const HomePage_SystemSettingsPage_LoginLogPage = () => {
    const paramsData = useRef<object>({ startTime: "", endTime: "" })
    let [pageNo, setPageNo] = useState<number>(1)
    let [pageSize, setPageSize] = useState<number>(10)
    const [sourceData, setSourceData] = useState<object>({})
    const columnList = [
        {
            title: '序号',
            width: 60,
            render: (text: string, record: object, idx: number) => idx + 1,
        },
        {
            title: '时间',
            minWidth: 60,
            dataIndex: 'datetime',
            render: (text: string) => text ?? "-"
        },
        {
            title: '操作账号',
            minWidth: 85,
            dataIndex: 'alterName',
            render: (text: string) => text ?? "-"
        },
        {
            title: '操作类型',
            minWidth: 85,
            dataIndex: 'opeType',
            render: (text: string) => text ?? "-"
        },
        {
            title: '操作描述',
            minWidth: 85,
            dataIndex: 'opeDes',
            render: (text: string) => text ?? "-"
        },
    ];

    const http_userSearchUserLog = () => {
        $Http("search", { typeName: "系统设置/操作日志", ...paramsData.current, pageNo, pageSize }).then((res) => {
            setSourceData({ ...res["data"] })
        })
    }

    const change_pagination = (no: number, size: number) => {
        pageNo = no
        pageSize = size
        setPageNo(pageNo)
        setPageSize(pageSize)
        http_userSearchUserLog()
    }

    // 广播函数数据
    const eventBusFuncData = {
        // 头部操作查询
        headerOperationSearch: (data: object) => {
            paramsData.current = data["data"]
            pageNo = 1
            http_userSearchUserLog()
            setPageNo(pageNo)
        }

    }
    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        http_userSearchUserLog()
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])
    return (
        <HomePage_TableComponent name="homePageSystemSettingsLoginLogPageTable" columnList={columnList} pageNo={pageNo} pageSize={pageSize} sourceData={sourceData} change_pagination={change_pagination} />
    )
}
export default HomePage_SystemSettingsPage_LoginLogPage